import { http, HttpResponse } from 'msw'
import Mock from 'mockjs'

// 增
export const addUser = http.post('/data/ed/user/createUser', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
// 改
export const editUser = http.put('/data/ed/user/updateUser', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
// 发布
export const publishUser = http.post('/data/ed/user/publish', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
// 删
export const deleteUser = http.post('/data/ed/user/deleteUser', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
// 查
export const userList = http.post('/data/ed/user/list', () => {
  let usrlist = Mock.mock({
    'list|100': [
      {
        userId: function () {
          return `user_${Mock.Random.increment()}`
        },
        userName: '@name',
        workNumber: '@string',
        mobile: '32314',
        userDept: '@string',
        userTitle: '@string',
        joinTime: '@date(yyyy-MM-dd)',
        gmtCreate: '@date(yyyy-MM-dd HH:mm:ss)',
        'isPublished|0-1': 1,
        internshipEndDate: '@date(yyyy-MM-dd)',
        userStatus: 'job',
      },
    ],
  })
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      userList: usrlist.list,
      totalCount: 100,
    },
  })
})
// 查单个
export const getUser = http.get(
  '/data/ed/user/getInfo/:userId',
  ({ params }) => {
    const { userId } = params
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {
        userId: userId,
        userName: '23name',
        workNumber: '342451',
        mobile: '32314',
        userDept: 'sfshtr',
        userTitle: 'aassd',
        joinTime: '2024-11-11',
        gmtCreate: '2024-11-11 14:00:23',
        isPublished: 0,
        internshipEndDate: '2024-11-11',
        userStatus: 'job',
      },
    })
  },
)

// 	校验用户信息 (用户id唯一)
export const checkUser = http.post('/data/ed/user/validateWorkNumber', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
